/*
 * ksBlock.cpp
 *
 *  Created on: Aug 3, 2011
 *      Author: wang
 */

#include "ksBlock.h"
#include <cstring>

//const static char* fileBlockStr = "file";

//#define kBlockFile      1
//#define kBlockMain      2
//#define kBlockPart      3

static const char* blockTypes[] = { //
        "File", //
                "Main", //
                "Part", //

                "Info", //
                "Cover", //
                "Catalog", //
                "Chapter", //
                "Pay", //
                "Resource", //
                "Content", //
                NULL };
const char* blockType2String(unsigned short id)
{
    return blockTypes[id - 1];
}
void safe_strcopy(char *dest, const char *sour, unsigned int capacity)
{
    if (!dest || !sour)
    {
        return;
    }

    unsigned int length = strlen(sour);
    if (length >= capacity)
    {
        length = capacity - 1;
    }
    memcpy(dest, sour, length);
    dest[length] = 0x00;
}

ksBlock::ksBlock()
{
    memset(&_blockHeader, 0, sizeof(BlockHeader));
}

ksBlock::~ksBlock()
{
}

unsigned char ksBlock::compress() const
{
    return _blockHeader.atom.compress;
}

unsigned char ksBlock::encrypt() const
{
    return _blockHeader.atom.encrypt;
}

unsigned short ksBlock::id() const
{
    return _blockHeader.atom.id;
}

unsigned short ksBlock::type() const
{
    return _blockHeader.atom.type;
}

void ksBlock::compress(unsigned char compress)
{
    _blockHeader.atom.compress = compress;
}

void ksBlock::encrypt(unsigned char encrypt)
{
    _blockHeader.atom.encrypt = encrypt;
}

void ksBlock::id(unsigned short id)
{
    // safe_strcopy(_blockHeader.atom.id, id, kBlockIDMaxLength);
    _blockHeader.atom.id = id;
}

void ksBlock::type(unsigned short type)
{
    //safe_strcopy(_blockHeader.atom.type, type, kBlockTypeMaxLength);
    _blockHeader.atom.type = type;
}
